﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ITPCTaxFormModel;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    //protected void Page_Init(object sender, EventArgs e)
    //{
    //    //Stop caching on IE
    //    //Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

    //    //Stop caching on FireFox
    //    //Response.Cache.SetNoStore();
    //}
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (var ctx = new ITPCTaxFormEntities()) {
                var pro_data = ctx.Product.Select(p => new { p.ProductID, p.ProductCode, p.Description });
                var procate_data = ctx.ProductCategory.Select(pc => new { pc.ProductCategoryID, pc.ProductCategoryCode, pc.Description });

                var _mtable = new List<Product>();
                foreach (var i in pro_data)
                    _mtable.Add(new Product
                    {
                        ProductID = i.ProductID.ToString(),
                        ProductCategoryID = "",
                        ProductCode = i.ProductCode.ToString(),
                        ProductCategoryCode = "",
                        SearchString = i.ProductCode.ToString() + " - " + i.Description.ToString()
                    }
                    );
                foreach (var i in procate_data)
                    _mtable.Add(new Product
                    {
                        ProductID = "",
                        ProductCategoryID = i.ProductCategoryID.ToString(),
                        ProductCode = "",
                        ProductCategoryCode = i.ProductCategoryCode.ToString(),
                        SearchString = i.ProductCategoryCode.ToString() + " - " + i.Description.ToString()
                    }
                    );
                Session["_mtable"] = _mtable;
            }
        }

    }
}